#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qregshape.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    envTimerId(-1)
{
    ui->setupUi(this);
    ui->environment->setGravity(ui->spnGravity->value());
    ui->triangle->sides(3);
    ui->square->sides(4);
    ui->pentagon->sides(5);
    ui->userPoly->sides(ui->spnSides->value());
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnTimer_toggled(bool checked)
{
    ui->btnTimer->setText(checked ? "Stop" : "Run");
    if(checked)
        envTimerId = ui->environment->startTimer(1000 / 40);
    else
        ui->environment->killTimer(envTimerId);
}

void MainWindow::on_environment_activeChanged(bool active)
{
    ui->propShape->setEnabled(active);
    ui->spnSize->setValue(ui->environment->getActiveSize());
    ui->spnMass->setValue(ui->environment->getActiveMass());
    ui->spnElastic->setValue(ui->environment->getActiveElasticity() * 100);
}

